//
//  HomeBaseCell.swift
//  DaRings
//
//  Created by 尹琼 on 2022/10/27.
//

import UIKit
import SnapKit
import MYModule

open class HomeBaseCell: TableViewCell {
    
    var selectedItem: (() ->Void)?
    
    public lazy var bgView: ImageView = {
        
        let bgView = ImageView()
        
        bgView.backgroundColor = UIColor.background
        
        return bgView
    }()
    
    public lazy var iconImagView: ImageView = {
        let iconImagView = ImageView()
        return iconImagView
    }()
    
    public lazy var titleLabel: Label = {
        let titleLabel = Label()
        titleLabel.numberOfLines = 0
        titleLabel.font = Fonts.boldSystemFont(ofSize: 20.0)
        titleLabel.textColor = UIColor.assist_222222
        return titleLabel
    }()
    
    public lazy var dateLabel: Label = {
        let dateLabel = Label()
        dateLabel.font = Fonts.today_assist_title_lv_2()
        dateLabel.textColor = UIColor.assist_D0D0D0
        return dateLabel
    }()
    
    public override func makeUI() {
        super.makeUI()
        
        
        self.backgroundColor = .clear
        self.contentView.backgroundColor = .clear
        
        bgView.layer.cornerRadius = 15.0
        bgView.layer.shadowColor = UIColor.init(hex: "#a6abbd").cgColor
        bgView.layer.shadowRadius = 30
        bgView.layer.shadowOffset = CGSize(width: -7.5, height: -7.5)
        bgView.layer.shadowOpacity = 0.35
        
        let tap = UITapGestureRecognizer(target: self, action: #selector(tapAction))
        bgView.isUserInteractionEnabled = true
        bgView.addGestureRecognizer(tap)

        
        self.contentView.addSubview(self.bgView)
        bgView.addSubview(iconImagView)
        bgView.addSubview(titleLabel)
        bgView.addSubview(dateLabel)
        
        
    
        bgView.snp.makeConstraints { make in
            
            make.left.equalToSuperview().offset(16)
            make.right.equalToSuperview().offset(-16)
            make.top.equalToSuperview()
            make.bottom.equalToSuperview().offset(-20)
            make.height.greaterThanOrEqualTo(90)
           
        }
        
        iconImagView.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(13)
            make.top.equalToSuperview().offset(13)
            
        }
        
        titleLabel.snp.makeConstraints { make in
            make.left.equalTo(iconImagView.snp.right).offset(15)
            make.top.equalToSuperview().offset(15)
        }
        
        dateLabel.snp.makeConstraints { make in
            make.left.equalTo(titleLabel.snp.left)
            make.top.equalTo(titleLabel.snp.bottom).offset(5.5)
        }
    }
    
    @objc func tapAction() {
        
        selectedItem?()
        
    }
    
    
    public func bind(to viewModel: ViewModel?) {
        
        
        
    }
    
    public func reloadData() {
        
        guard let tableView = superview as? UITableView, let indexPath = tableView.indexPath(for: self) else { return }
        tableView.reloadRows(at: [indexPath], with: .none)
        
    }
    
//    open override func layoutSubviews() {
//        super.layoutSubviews()
//
//        if contentView.frame.width == self.bounds.width {
//
//            var frame = contentView.frame
//            frame.origin.x = frame.origin.x + 16
//            frame.size.width = frame.size.width - 32
//
//            frame.size.height = frame.size.height - 20
//            contentView.frame = frame
//
//        }
//
//    }
    
    
    

}
